from flask import Blueprint, jsonify, request
from random import *

# api = Blueprint('app', __name__, subdomain='api')
api = Blueprint('app', __name__)


@api.route('/')
def hello_world():
    # 1/0
    return 'Hello, World!'


@api.route('/random')
def random_number():
    response = {
        'randomNumber': randint(1, 100)
    }
    return jsonify(response)


@api.route("/login", methods=['POST'])
def login():
    data = request.get_json()
    username = data['username']
    password = data['password']
    response = {
        'code': -1,
        'msg': 'login failed'
    }
    if Auth.login(username, password):
        response = {
            'code': 0,
            'msg': 'login success'
        }
    return jsonify({"login": response})  # 返回布尔值


class Auth(object):
    @staticmethod
    def login(username, password):
        return 'pass'
